from appium import webdriver
from appium.options.common import AppiumOptions


class Base:
    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, "instance"):
            cls.instance = object.__new__(cls)
        return cls.instance

    def __init__(self):
        if not hasattr(self, "driver"):
            self.driver = None

    def create_driver(self):
        options = AppiumOptions()
        options.load_capabilities({
            "platformName": "Android",
            "appium:automationName": "UiAutomator2",
            "appium:ensureWebviewsHavePages": True,
            "appium:nativeWebScreenshot": True,
            "appium:newCommandTimeout": 3600,
            "appium:noReset": True,
            "appium:connectHardwareKeyboard": True,
            "appium:appPackage": "com.xiaomi.shop",
            "appium:appActivity": ".activity.MainTabActivity "
        })
        self.driver = webdriver.Remote("http://127.0.0.1:4723", options=options)
        self.driver.implicitly_wait(15)

    def get_driver(self):
        return self.driver

base = Base()
base.create_driver()
DRIVER = base.get_driver()